import os
from celery import Celery
from config import ProductConfig,DevelopmentConfig
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from flask_mail import Mail
from flask_moment import Moment
from flask_ckeditor import CKEditor
from flask_login import LoginManager
from flask_avatars import Avatars
from flask_whooshee import Whooshee
from models import RoutingSQlAlchemy

whooshee = Whooshee()
avatars = Avatars()
bootstrap = Bootstrap()
mail = Mail()
moment = Moment()
db = RoutingSQlAlchemy()
ckeditor = CKEditor()
login_manager = LoginManager()
login_manager.login_view = 'admin.login'
login_manager.login_message_category = 'waring'
login_manager.login_message = '请先登陆才能观察这部分内容'


if os.getenv('CELERY_CONFIG') == 'product':
    celery = Celery(__name__,broker=ProductConfig.CELERY_BROKER_URL,
                    backend=ProductConfig.RESULT_BACKEND)
else:
    celery = Celery(__name__, broker=DevelopmentConfig.CELERY_BROKER_URL,
                    backend=DevelopmentConfig.RESULT_BACKEND)